#include "burgers.h"
#include  <cmath>

/*----------------------------------------------------------*/

Burgers::Burgers() : ProblemInterface()
{
}

/*----------------------------------------------------------*/

void Burgers::initialCondition(Vector& u0, double x) const
{
  // création d'un choc
  // u0[0]=sin(M_PI*(x+0.5));
  // return;
  
  // détente
  if(x < 0.5)
  {
    u0[0] = -1.0;
  }
  else
  {
    u0[0] = 1.0;
  }
  return;
  
  // choc stationnaire
  if(x < 0.5)
  {
    u0[0] = 1.0;
  }
  else
  {
    u0[0] = -1.0;
  }
}

/*----------------------------------------------------------*/

void Burgers::flux(Vector& flux, const Vector& u) const
{
  flux[0] = 0.5*u[0]*u[0];
}

/*----------------------------------------------------------*/

void Burgers::boundaryfluxleft(Vector& flux, const Vector& u) const
{
  if(u[0]>0.0)
  {
    flux[0] = 0.5;     
  }
  else
  {
    flux[0] = 0.5*u[0]*u[0];     
  }
}

/*----------------------------------------------------------*/

void Burgers::boundaryfluxright(Vector& flux, const Vector& u) const
{
  if(u[0]>0.0)
  {
    flux[0] = 0.5*u[0]*u[0];     
  }
  else
  {
    flux[0] = 0.5;     
  }
}

/*----------------------------------------------------------*/

void Burgers::interiorflux(Vector& flux, const Vector& ul, const Vector& ur) const
{
  flux[0] = 0.5*(0.5*ul[0]*ul[0]+0.5*ur[0]*ur[0]) + 0.25*(fabs(ul[0])+fabs(ur[0]))*(ul[0]-ur[0]);
}

